var categoryService = require('../categoryService');

module.exports.tryEvent = function (client) {

	client.on('getAllCategories', function(short, callback) {
        console.log('categorySioController: evento getAllCategories recibido');
        try {
	        categoryService.getAll(short, callback);
	    } catch (err) {
	    	console.log('ERROR: categorySioController getAll. Detalle: ' + err);
	    }
    });

    client.on('findCategories', function(filters, callback) {
        console.log('categorySioController: evento findCategories recibido');
        try {
	        categoryService.find(filters, callback);
	    } catch (err) {
	    	console.log('ERROR: categorySioController find. Detalle: ' + err);
	    }
    });

	client.on('findOneCategory', function(filters, callback) {
        console.log('categorySioController: evento findOneCategory recibido');
        try {
	        categoryService.findOne(filters, callback);
	    } catch (err) {
	    	console.log('ERROR: categorySioController findOne. Detalle: ' + err);
	    }
    });    

    client.on('saveCategory', function(category, callback) {
        console.log('categorySioController: evento saveCategory recibido');
        try {
	        categoryService.save(category, callback);
	    } catch (err) {
	    	console.log('ERROR: categorySioController save. Detalle: ' + err);
	    	callback(err);
	    }
    });

	client.on('removeCategory', function(category, callback) {
        console.log('categorySioController: evento removeCategory recibido');
        try {
	        categoryService.remove(category.id, callback);
	    } catch (err) {
	    	console.log('ERROR: categorySioController remove. Detalle: ' + err);
	    }
    });    
}